﻿using System;
using System.ComponentModel;
using SweeperPrototype.Business.Fields;
using SweeperPrototype.Business.Keys;
using SweeperPrototype.Objects;

namespace SweeperPrototype.GUI.EffectiveExposures
{
    public class EffectiveExposureViewModel : BaseVM
    {
        private static readonly PropertyChangedEventArgs ARGS = new PropertyChangedEventArgs(null);
        public static readonly PropertyChangedEventArgs ARGS_ISSELECTED = new PropertyChangedEventArgs("IsSelected");

        private readonly EffectiveExposure m_CoreEffectiveExposure;

        public EffectiveExposureViewModel(EffectiveExposure core_effective_exposure)
        {
            m_CoreEffectiveExposure = core_effective_exposure;
            m_CoreEffectiveExposure.Updated += HandleUpdate;
        }

        private void HandleUpdate(EffectiveExposure source, EffectiveExposure.EffectiveExposureUpdate new_update, EffectiveExposure.EffectiveExposureUpdate old_update)
        {
            FirePropertyChanged(ARGS);
        }

        public EffectiveExposure CoreEffectiveExposure
        {
            get { return m_CoreEffectiveExposure; }
        }

        public BookCode BookCode
        {
            get { return m_CoreEffectiveExposure.BookCode; }
        }

        public ExposureRIC RIC
        {
            get { return m_CoreEffectiveExposure.RIC; }
        }

        public ExposureRIC ExposureRIC
        {
            get { return m_CoreEffectiveExposure.ExposureRIC; }
        }

        public EffectiveRIC EffectiveRIC
        {
            get { return m_CoreEffectiveExposure.EffectiveRIC; }
        }

        public Shares Quantity
        {
            get { return m_CoreEffectiveExposure.Quantity; }
        }

        public Multiplier Multiplier
        {
            get { return m_CoreEffectiveExposure.Multiplier; }
        }

        public Timestamp Timestamp
        {
            get { return m_CoreEffectiveExposure.Timestamp; }
        }

        public bool IsValid
        {
            get { return m_CoreEffectiveExposure.IsValid; }
        }


        private bool m_IsSelected;

        public bool IsSelected
        {
            get { return m_IsSelected; }
            set
            {
                if (m_IsSelected == value) return;

                m_IsSelected = value;
                FirePropertyChanged(ARGS_ISSELECTED);
            }
        }
    }
}